<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>登录</title>
        <link rel="stylesheet" href="/css/login.css">
        <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css">
    </head>
    <style>
        #p1{
            font-size: 32px;
            color: green;
        }
    </style>
    <body>
    <div class="layui-form">
        <div class="login">
            <p align="center" id="p1">登录页面</p>
            <form>
                <div class="name">
                    用户名：<input type="text" lay-verify="required" id="name" name="username">
                    <p></p>
                </div>
                <div class="pwd">
                    密码：<input type="password" lay-verify="pass" id="pwd" name="password">
                    <p></p>
                </div>
                <div class="btn-red">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
                </div>
            </form>
        </div>
        <script src="/layuiadmin/layui/layui.js"></script>
        <script>
            layui.config({
                base: '/layuiadmin/' //静态资源所在路径
            }).extend({
                index: 'lib/index' //主入口模块
            }).use(['index', 'user','jquery','layer'], function(){
                var $ = layui.$
                    ,setter = layui.setter
                    ,admin = layui.admin
                    ,form = layui.form
                    ,router = layui.router()
                    ,layer=layui.layer
                    ,jquery=layui.jquery
                    ,search = router.search;
                form.render();

                //提交
                form.on('submit(LAY-user-login-submit)', function(obj){
                    var username=$("#name").val();
                    var password=$("#pwd").val();
                    $.ajax({
                        url:"/user/login1",
                        data:{"username":username,"password":password},
                        success:function (result) {
                            if(result=="success"){
                                layer.msg("登录成功",{
                                       offset:'15px'
                                       ,icon:1
                                       ,time:2000
                                    }, function () {
                                    location.href="/user/main";
                                });
                            }
                            if(result=="error"){
                                layer.msg("用户名或则密码错误");

                            }
                        },
                        error:function (errorMsg) {
                            alert("出错了");
                        }
                    });
                    return false;
                });


            });
        </script>
    </div>
    </body>
</html>